package org.yaac.client.service;

import java.util.Collection;
import java.util.List;

import org.yaac.shared.YaacException;
import org.yaac.shared.crud.MetaNamespace;
import org.yaac.shared.editor.EntityHierarchy;
import org.yaac.shared.editor.EntityInfo;
import org.yaac.shared.editor.EntityUpdateInfo;
import org.yaac.shared.property.KeyInfo;
import org.yaac.shared.property.PropertyInfo;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
@RemoteServiceRelativePath("GWT.rpc")
public interface CRUDService extends RemoteService {

	/**
	 * 
	 */
	public static final String META_NAMESPACE = "__namespace__";
	
	/**
	 * 
	 */
	public static final String META_KIND = "__kind__";
	
	/**
	 * 
	 */
	public static final String META_PROPERTY = "__property__";
	
	/**
	 * @return
	 */
	List<MetaNamespace> loadMetaData();

	/**
	 * @param kind
	 * @param filter
	 * @param start
	 * @param length
	 * @return
	 * @throws YaacException
	 */
	List<EntityInfo> loadEntities(String kind, String filter, int start, int length) throws YaacException;
	
	/**
	 * load full hierarchy for the entity
	 * 
	 * @param keyString
	 * @return
	 * @throws YaacException on invalid keystring
	 */
	EntityHierarchy loadEntityHierarchy(String keyString) throws YaacException;
	
	/**
	 * @param entities
	 */
	void updateEntity(Collection<EntityUpdateInfo> entities);

	/**
	 * @param keys
	 */
	void delete(KeyInfo keys);
	
	/**
	 * @param keys
	 * @return
	 * @throws YaacException when the requested entity does not exist
	 */
	String copyToNew(KeyInfo keyInfo) throws YaacException;
	
	/**
	 * parse a string expression to property info
	 * this is used when user is editing properties
	 * 
	 * @param keyString
	 * @param exp
	 * @param files to process file uploads
	 * @return
	 * @throws YaacException
	 */
	PropertyInfo parsePropertyExp(String keyString, String exp, List<String> filePaths) throws YaacException;
	
	void create(KeyInfo key);
}
